var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var deviceone = require("deviceone");
var qqHttp = require("helper/http");
var helperOpen = require("helper/open");
var activityUrl = require("url/activity");
var httpUrl = activityUrl.url.sign.page;
var rootview = ui("$");
var listdata = mm("do_ListData");
var noData = [{"template":1}];
//定义变量
var page = 1;
// UI
var listView = ui("listView");
var alayoutRoot = ui("alayoutRoot");
var headerAout = ui("headerAout");
var listView = ui("listView");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
// andriod返回键
do_Page.on("back", function() {
	do_App.closePage();
});
/** **************处理页面-头部-begin**************** */
// 左上角-返回
var headerLeft = ui(addheader + ".headerLeft");
headerLeft.on("touch", function() {
	do_App.closePage()
});
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "报名列表"
})
header.refreshData();
/** **************处理页面-头部-end**************** */

listView.bindItems(listdata);

var type, activityId;
do_Page.on("loaded", function() {
	// 读取当前页面的传入参数
	activityId = do_Page.getData().activityId;
	laodPage();
});

//刷新数据
function laodPage() {
	page = 1;
	var params = {
		page : page,
		activityId:activityId
	};
	qqHttp.post(httpUrl, params, function(data) {
		listView.rebound();
		listdata.removeAll();
		if(data.page.content.length){
			listdata.addData(data.page.content);
		}
		else{
			listdata.addData(noData);
		}
		listView.refreshItems();
	})
}
// 刷新数据
function getNextPageData() {
	page++;
	var params = {
		page : page,
		activityId:activityId
	};
	qqHttp.post(httpUrl, params, function(data) {
		listView.rebound();
		listdata.addData(data.page.content);
		listView.refreshItems();
	})
}
//下拉列表，刷新数据
listView.on("pull", function(data) {
	if (data.state == 2) {
		laodPage();
	}
});

// 上拉列表，翻页数据
listView.on("push", function(data) {
	if (data.state == 2) {
		getNextPageData();
	}
});
do_Page.on("result", function(data) {
	// 更新远程最新数据
	laodPage();
});
